package com.jcl.recruit.searchresume.logic;

import com.jcl.recruit.searchresume.mapper.SearchResumeMapper;
import com.jcl.recruit.searchresume.model.SearchResume;
import com.jcl.recruit.searchresume.model.SearchResumeRecord;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName SearchResumeLogic
 * @Description TODO
 * @Author yyliu
 * @Date 2018/10/25 15:02
 * @Version 1.0
 **/
@Component
public class SearchResumeLogic implements SearchResumeMapper {

    @Autowired
    private SearchResumeMapper       searchResumeMapper;

    @Override
    public List<SearchResume> findListByNotInId(List<Integer> ids) {
        return searchResumeMapper.findListByNotInId(ids);
    }

    @Override
    public List<Map<String, Object>> selectRecommendSearchResumesByRecord(SearchResumeRecord record, String channel) {
        return searchResumeMapper.selectRecommendSearchResumesByRecord(record, channel);
    }

    @Override
    public List<Map<String, Object>> selectRecommendSearchResumesByCondition(List<SearchResumeRecord> records,
                                                                             String channel) {

        return searchResumeMapper.selectRecommendSearchResumesByCondition(records, channel);
    }

    @Override
    public Map<String, Object> selectRecommendSearchResumesCountByCondition(List<SearchResumeRecord> records) {
        return searchResumeMapper.selectRecommendSearchResumesCountByCondition(records);
    }

    @Override
    public Map<String, Object> testRecommendSearchResumesCountByCondition(List<SearchResumeRecord> records, Date startTime, Date endTime) {
        return searchResumeMapper.testRecommendSearchResumesCountByCondition(records, startTime, endTime);
    }

    @Override
    public List<Map<String,Object>> selectSearchResumesByCondition(String keyword, String eduLastEducation, String city,Integer workyear,Integer status) {
        List<Map<String,Object>> list = searchResumeMapper.selectSearchResumesByCondition(keyword,eduLastEducation,city,workyear,status);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(Map<String,Object> entity:list){
            entity.put("update_date",sdf.format(entity.get("update_date")));
        }
        return list;
    }


    @Override
    public Map<String, Object> selectPrimaryKeyById(Integer id) {
        Map<String,Object> entity = searchResumeMapper.selectPrimaryKeyById(id);
        return entity;
    }

    @Override
    public SearchResume selectSearchResumeById(Integer id) {
        return searchResumeMapper.selectSearchResumeById(id);
    }

    @Override
    public int insertSelective(SearchResume record) {
        return searchResumeMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(SearchResume record) {
        return searchResumeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int selectCountBySearchResume(SearchResume entity) {
        return searchResumeMapper.selectCountBySearchResume(entity);
    }

    @Override
    public int selectCountByZhiPinSearchResume(SearchResume entity) {
        return searchResumeMapper.selectCountByZhiPinSearchResume(entity);
    }

    @Override
    public List<Map<String, String>> selectPrimarykeyByDatesAndSources(Boolean today) {
        return searchResumeMapper.selectPrimarykeyByDatesAndSources(today);
    }

    //用于查询重复数据
    @Override
    public List<SearchResume> selectChongfu() {
        return searchResumeMapper.selectChongfu();
    }

    //用于批量删除重复数据
    @Override
    public int batchDelete(List<SearchResume> searchResumes) {
        searchResumes = this.selectChongfu();
        if(searchResumes.size() > 0) {
            return searchResumeMapper.batchDelete(searchResumes);
        }else {
            return 0;
        }
    }

    @Override
    public int batchDeleteByIds(List<Integer> ids) {
        if(CollectionUtils.isNotEmpty(ids)){
           return searchResumeMapper.batchDeleteByIds(ids);
        }
        return 0;
    }
}
